package org.qf.Test;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.qf.Dao.supermarketDao;
import org.qf.entity.supermarket;
import java.io.IOException;
import java.io.InputStream;
//测试类
public class Addtest {
    public static void main(String[] args) {
//1.加载mybatis核心配置文件
        try {
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
//2.获取会话工厂
            SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
            SqlSessionFactory factory=builder.build(inputStream);
//3.获取会话
            SqlSession session = factory.openSession();
//4. 获取dao接口
            supermarketDao supermarketDao = session.getMapper(supermarketDao.class);
            supermarket supermarket=new supermarket();
            supermarket.setStuNum("005");
            supermarket.setStuName("苹果");
            supermarket.setStuType("水果");
            supermarket.setStuWeight(10);
            int i = supermarketDao.addStu(supermarket);
//增加、删除、修改需要事务提交
            session.commit();
            if(i>0){
                System.out.println("增加成功");
            }else{
                System.out.println("增加失败");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}